﻿{	
	var r = new RegExp("(^|(.*?\\/))(selHDKQFWDJXM.js)(\\?|$)"),
	s = document.getElementsByTagName('script'),
	src, m, baseurl = "";
	for(var i=0, len=s.length; i<len; i++) {
		src = s[i].getAttribute('src');
		if(src) {var m = src.match(r);if(m) {baseurl = m[1];break;}}}
    inputCSS('sty.css');
}
function inputCSS(style){
    var css='<'+'link rel="stylesheet" href="'+baseurl+style+'"><'+'/>'; 
    document.writeln(css);
}
function selDJXM()
{
    this.tableName="划定矿区范围";
    this.pagedata=new SmPageData("CKQDJK","划定矿区范围");
    var _self=this;    
    this.okcallback=null;
    var strhtml='<div class="cls_container" id="id_div_seldjxm_div""><div><div id="id_div_query" class="queryform"><div style="margin-top: 20px; margin-left: 20px;">\
                <label>矿区名称：</label><input id="id_input_query_ksmc" class="text" /><label>勘察许可证号：</label><input id="id_input_query_xkzh" class="text" />\
                <label>申请人：</label><input id="id_input_query_sqr" class="text" /><label>划矿备案号：</label><input id="id_input_query_hkbah" class="text" />\
                <input type="button" class="btnnnn"/></div></div><hr style="border: 1 dashed #987cb9" width="98%" color="white" size="1" />\
                <div class="resultform" style="overflow-y:auto;height:360px;"><table id="id_table_selectdjxm" border="1px solid" ></table></div><div id="id_div_pagecontrol" class="go_mod_page">\
                <p id="id_select_djxm_pagecontrol" style="float: right; margin-right: 10px;margin-bottom:1px;" class="page_right"></p></div></div></div>';
    this.Show=function (callback)
    {
        this.okcallback=callback
        $("#id_div_seldjxm_div").remove();
        $("body").append(strhtml);
        $("#id_div_seldjxm_div" ).dialog({title:"选择划定矿区范围登记项目",position: "top",autoOpen: false,close:funCancel,top:50,width:960,buttons:{"确定": funOK,"取消":function(){$("#id_div_seldjxm_div" ).dialog("close" );}}});
        $("#id_div_seldjxm_div" ).dialog("open");
        $("#id_div_seldjxm_div" ).css("height","510px");
        document.getElementById("id_div_seldjxm_div" ).parentNode.style["background"]="#f8fae9";
        document.getElementById("id_div_seldjxm_div" ).parentNode.style["background-color"]="#f8fae9";
        document.getElementById("id_div_seldjxm_div" ).parentNode.style["border"]="2px solid rgb(166, 201, 226)";
        _self.pagedata.PageSize=15;
        _self.pagedata.Key="BSM";
        _self.pagedata.Filter=getFilter();
        _self.pagedata.Fields="hkbah as 划矿备案号,矿区名称 as 矿区名称,申请人 as 申请人,\
        QFSJ AS 签发日期,有效期起 AS 有效期起,有效期止 AS 有效期止,矿区面积 AS 矿区面积,开采主矿种 AS 开采主矿种,填表人 as 填表人";
        _self.pagedata.InitEx();
        $("input:.btnnnn").click(function (){btnquery();});
        if(_self.pagedata!=null)
        {
            var str="<tr class='head'><th class='th'>序号</th>";
            if(_self.pagedata.Data!=null)
            {
                for(i=0;i<_self.pagedata.Data.Captions.length-1;i++)
                {
                    str+="<th class='th'>"+_self.pagedata.Data.Captions[i]+"</th>";    
                }
                str+="</tr>";
                if(_self.pagedata.Data.Rows.length>0)
                {
                    for(i=0;i<_self.pagedata.Data.Rows.length;i++)
                    {
                        str+="<tr><th class='th2'>"+(i+1)+"</th>";
                        for(j=0;j<_self.pagedata.Data.Captions.length-1;j++)
                        {
                            str+="<td>"+_self.pagedata.Data.Rows[i][j]+"</td>";
                        }   
                        str+="</tr>";
                    }
                }
                $("#id_table_selectdjxm").append(str);
            }
            InitPageControlEx();
        }
    }
    function funOK() 
    {
        if($("#id_div_seldjxm_div tr:.selected not(.head)")!=null)
        {
            if($("#id_div_seldjxm_div tr:.selected:not(.head)").length==1)
            {
                if(_self.okcallback!=null)
                {
                    var xh=parseInt($("#id_div_seldjxm_div tr:.selected:not(.head) th:first").text());
                    var i=0;
                    var obj;
                    var str="{";
                    for(i=0;i<_self.pagedata.Data.Captions.length;i++)
                    {
                        str+='"'+_self.pagedata.Data.Captions[i]+'":"'+_self.pagedata.Data.Rows[xh-1][i]+'",';
                    }
                    str=str.substr(0,str.length-1)+"}";
                    obj=JSON.parse(str);
                    if(_self.okcallback!=null)
                    {
                        _self.okcallback(obj);
                    }
                    $("#id_div_seldjxm_div" ).dialog("close" );
                }
            }
        }
    }
    function funCancel() 
    {
        $("#id_div_seldjxm_div").remove();
    }
    function InitPage()
    {
        $("#id_div_seldjxm_div tr:not(.head)").remove();
        if(_self.pagedata!=null)
        {
            var str='';
            if(_self.pagedata.Data.Rows.length>0)
            {
                for(i=0;i<_self.pagedata.Data.Rows.length;i++)
                {
                    str+="<tr><th class='th2'>"+(i+1)+"</th>";
                    for(j=0;j<_self.pagedata.Data.Captions.length-1;j++)
                    {
                        str+="<td><span>"+_self.pagedata.Data.Rows[i][j]+"</span></td>";
                    }   
                    str+="</tr>";
                }
            }
            $("#id_table_selectdjxm").append(str);
        }
        InitPageControlEx();
    }
    function btnquery()
    {
        var strfilter=getFilter();
        _self.pagedata.Filter=strfilter;
        _self.pagedata.InitEx();
        InitPage();
    }
    function page(pageindex)
    {
        if(pageindex!=_self.pagedata.PageIndex)
        {        
            _self.pagedata.PageIndex=pageindex;
            btnquery();
        }
    }
    function getFilter()
    {
        var str='';
        var ksmc=$("#id_input_query_ksmc").val();
        var xkzh=$("#id_input_query_xkzh").val();
        var sqr=$("#id_input_query_sqr").val();
        var hkbah=$("#id_input_query_hkbah").val();
        if(ksmc!=null && ksmc!='')
        {
            str+=" 矿区名称 like \\\'%"+ksmc+"%\\\' and";
        }
        if(xkzh!=null && xkzh!='')
        {
            str+=" kcxkzh like \\\'%"+xkzh+"%\\\' and";
        }
        if(sqr!=null && sqr!='')
        {
            str+=" 申请人 like \\\'%"+sqr+"%\\\' and";
        }
        if(hkbah!=null && hkbah!='')
        {
             str+=" hkbah like \\\'%"+hkbah+"%\\\' and";
         }
         str += " XMZT=0 AND 项目类型=1010 and";
        if(str!='')
        {
            str=str.substr(0,str.length-3);
        }
        return str;
    }
    function InitPageControlEx()
    {
        $("#id_div_seldjxm_div tr").click(function(){$("#id_div_seldjxm_div tr.selected").removeClass("selected");$(this).addClass("selected");});
        $("#id_div_seldjxm_div tr").dblclick(function(){funOK();});
        var ele=$("#id_select_djxm_pagecontrol");
        var strPre=_self.pagedata.PageIndex==1?'<span class="prev" ><span></span>上一页</span>&nbsp;':'<a  title="上一页" class="prev"><span></span>上一页</a>';
        ele.html(strPre);
        if(_self.pagedata.PageCount<=7)
        {
            for(i=1;i<=_self.pagedata.PageCount;i++)
            {
                 ele.append('<a title="第'+i+'页">'+i+'</a>&nbsp;');
            }
        }
        else
        {
            if(_self.pagedata.PageIndex>=5)
            {
                ele.append('<a title="第'+1+'页">'+1+'</a>&nbsp;');
                ele.append('<span class="point">...</span>');
                if(_self.pagedata.PageIndex<_self.pagedata.PageCount-3)
                {
                    for(j=_self.pagedata.PageIndex-2;j<=_self.pagedata.PageIndex+2;j++)
                    {
                       ele.append('<a title="第'+j+'页">'+j+'</a>&nbsp;');
                    }
                    ele.append('<span class="point">...</span>');
                    ele.append('<a title="第'+_self.pagedata.PageCount+'页">'+_self.pagedata.PageCount+'</a>&nbsp;');
                }
                else
                {
                    for(j=_self.pagedata.PageCount-5;j<=_self.pagedata.PageCount;j++)
                    {
                        ele.append('<a title="第'+j+'页">'+j+'</a>&nbsp;');
                    }
                }
            }
            else
            {
                for(j=1;j<=6;j++)
                {
                    ele.append('<a title="第'+j+'页">'+j+'</a>&nbsp;');
                }
                ele.append('<span class="point">...</span>');
                ele.append('<a title="第'+_self.pagedata.PageCount+'页">'+_self.pagedata.PageCount+'</a>&nbsp;');
            }
        }
        $("#id_select_djxm_pagecontrol").css("cursor","pointer");
        var strNext=_self.pagedata.PageIndex==_self.pagedata.PageCount || _self.pagedata.PageCount==0?'<span class="next" ><span></span>下一页</span>':'<a title="下一页" class="next"><span></span>下一页</a>';
        ele.append(strNext);
        $("#id_select_djxm_pagecontrol a").click(function (){var tit=$(this).attr("title");if(tit=="上一页"){page(_self.pagedata.PageIndex-1);}else if(tit=="下一页"){page(_self.pagedata.PageIndex+1);}else{page(parseInt(tit.substr(1,tit.length-2)));}});
        $('a[title="第'+_self.pagedata.PageIndex+'页"]').addClass("current");
    } 
}
